#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //放图片
    QPixmap pix("C:\\Users\\hyb\\Desktop\\qt-learning\\QTonline\\Timer\\1.png");
    ui->label->setPixmap(pix);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_startButton_clicked()
{
    myTimerId=this->startTimer(TIMEOUT);//开启定时器
}

void Widget::timerEvent(QTimerEvent *event)
{
    if(event->timerId() == myTimerId)
    {
        picId++;
        if(picId==3)picId=1;
        QString path="C:\\Users\\hyb\\Desktop\\qt-learning\\QTonline\\Timer\\";
        path += QString::number(picId);
        path += ".png";

        QPixmap pix(path);
        ui->label->setPixmap(pix);
        mytime++;//时间
        ui->lineEdit->setText(QString::number(mytime));//将整形转换为字符串
    }
}

void Widget::on_pushButton_2_clicked()
{
    this->killTimer(myTimerId);//停止定时器
}
